#include <stdio.h>
#include <stdlib.h>
#include <string.h>

#include "nnslite.h"
#include "nnslitetest.h"

static int cmd_createStore(const char* storename, const char* filename)
{
	s32 ret;
	nnsliteStore store;
	ret = nnsliteStoreCreate(&store, storename, NULL);
	if(NNSLITE_FAILED(ret))
	{
		printf("Cannot create the store : %s \n", storename);
		return -1;
	}
	ret = nnsliteStoreSave(&store, filename);
	if(NNSLITE_FAILED(ret))
	{
		printf("Cannot save the store : %s to file : %s \n", storename, filename);
		return -1;
	}
	return 0;
}

static int cmd_openStore(const char* filename, nnsliteStore* store)
{
	return nnsliteStoreOpen(store, filename);
}

static void printUsage()
{
	printf("\tcreate %storename% %filename%\n");
}

static int console_exec(int argc, char* argv[])
{
	nnsliteStore* curStore = NULL;
	if (argc < 2)
	{
		printUsage();
		return 0;
	}
	if (stricmp(argv[1], "create") == 0)
	{
		cmd_createStore(argv[2],argv[3]);
	}
	else if(stricmp(argv[1],"open") ==0)
	{
		if (curStore != NULL)
			nnsliteStoreFree(curStore);
		cmd_openStore(argv[2], curStore);
	}
	else
		printUsage();
	return 0;
}

int main(int argc, char* argv[])
{
	// console_exec(argc, argv);
	nnslitetest_1();
	return 0;
}
